package com.test.security.springsecuritydemo5.config;

import com.test.security.springsecuritydemo5.service.CustomAuthenticationFailureHandler;
import com.test.security.springsecuritydemo5.service.CustomAuthenticationSuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2022/12/29-22:35
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@Configuration
public class ProjectConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private CustomAuthenticationSuccessHandler successHandler;
    @Autowired
    private CustomAuthenticationFailureHandler failureHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .successHandler(successHandler)
                .failureHandler(failureHandler)
                .and()
                .httpBasic();
        http.authorizeRequests()
                .anyRequest().authenticated();
    }
}
